<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>module SyntaxSuggest - syntax_suggest: Ruby Standard Library Documentation</title>


<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>

<script src="./js/jquery-3.2.0.min.js"></script>

<script src="./js/vue.min.js"></script>
<script src="./js/js.cookie.min.js"></script>

<link href="./css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="./css/rdoc.css" rel="stylesheet">
<link href="./css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
  var index_rel_prefix = "./";
  var darkModeCsseHref = "./css/rdoc-dm.css"
  var defaultModeCssHref = "./css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="module">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="./index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    

    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-call">::call</a>
    <li ><a href="#method-c-handle_error">::handle_error</a>
    <li ><a href="#method-c-invalid-3F">::invalid?</a>
    <li ><a href="#method-c-module_for_detailed_message">::module_for_detailed_message</a>
    <li ><a href="#method-c-record_dir">::record_dir</a>
    <li ><a href="#method-c-valid-3F">::valid?</a>
    <li ><a href="#method-c-valid_without-3F">::valid_without?</a>
    <li class="calls-super" ><a href="#method-i-detailed_message">#detailed_message</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="module-SyntaxSuggest">
    <h1 id="module-SyntaxSuggest" class="module">
      module SyntaxSuggest
    </h1>

    <section class="description">
    
    </section>

      <section id="5Buntitled-5D" class="documentation-section">


      <section class="constants-list">
      <header>
      <h3>Constants</h3>
      </header>
      <dl>
          <dt id="DEFAULT_VALUE">DEFAULT_VALUE
          <dd><p>Used to indicate a default value that cannot be confused with another input.</p>
          <dt id="TIMEOUT_DEFAULT">TIMEOUT_DEFAULT
          <dd>
          <dt id="VERSION">VERSION
          <dd>
        </dl>
        </section>



                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-call" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">call</span><span
                                class="method-args">(source:, filename: DEFAULT_VALUE, terminal: DEFAULT_VALUE, record_dir: DEFAULT_VALUE, timeout: TIMEOUT_DEFAULT, io: $stderr)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p><a href="SyntaxSuggest.html#method-c-call"><code>SyntaxSuggest.call</code></a> [Private]</p>

<p>Main private interface</p>

                              <div class="method-source-code" id="call-source">
            <pre><span class="ruby-comment"># File syntax_suggest/api.rb, line 64</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">call</span>(<span class="ruby-value">source:</span>, <span class="ruby-value">filename:</span> <span class="ruby-constant">DEFAULT_VALUE</span>, <span class="ruby-value">terminal:</span> <span class="ruby-constant">DEFAULT_VALUE</span>, <span class="ruby-value">record_dir:</span> <span class="ruby-constant">DEFAULT_VALUE</span>, <span class="ruby-value">timeout:</span> <span class="ruby-constant">TIMEOUT_DEFAULT</span>, <span class="ruby-value">io:</span> <span class="ruby-identifier">$stderr</span>)
  <span class="ruby-identifier">search</span> = <span class="ruby-keyword">nil</span>
  <span class="ruby-identifier">filename</span> = <span class="ruby-keyword">nil</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">filename</span> <span class="ruby-operator">==</span> <span class="ruby-constant">DEFAULT_VALUE</span>
  <span class="ruby-constant">Timeout</span>.<span class="ruby-identifier">timeout</span>(<span class="ruby-identifier">timeout</span>) <span class="ruby-keyword">do</span>
    <span class="ruby-identifier">record_dir</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">ENV</span>[<span class="ruby-string">&quot;DEBUG&quot;</span>] <span class="ruby-operator">?</span> <span class="ruby-string">&quot;tmp&quot;</span> <span class="ruby-operator">:</span> <span class="ruby-keyword">nil</span>
    <span class="ruby-identifier">search</span> = <span class="ruby-constant">CodeSearch</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">source</span>, <span class="ruby-value">record_dir:</span> <span class="ruby-identifier">record_dir</span>).<span class="ruby-identifier">call</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">blocks</span> = <span class="ruby-identifier">search</span>.<span class="ruby-identifier">invalid_blocks</span>
  <span class="ruby-constant">DisplayInvalidBlocks</span>.<span class="ruby-identifier">new</span>(
    <span class="ruby-value">io:</span> <span class="ruby-identifier">io</span>,
    <span class="ruby-value">blocks:</span> <span class="ruby-identifier">blocks</span>,
    <span class="ruby-value">filename:</span> <span class="ruby-identifier">filename</span>,
    <span class="ruby-value">terminal:</span> <span class="ruby-identifier">terminal</span>,
    <span class="ruby-value">code_lines:</span> <span class="ruby-identifier">search</span>.<span class="ruby-identifier">code_lines</span>
  ).<span class="ruby-identifier">call</span>
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">Timeout</span><span class="ruby-operator">::</span><span class="ruby-constant">Error</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">e</span>
  <span class="ruby-identifier">io</span>.<span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Search timed out SYNTAX_SUGGEST_TIMEOUT=#{timeout}, run with SYNTAX_SUGGEST_DEBUG=1 for more info&quot;</span>
  <span class="ruby-identifier">io</span>.<span class="ruby-identifier">puts</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">backtrace</span>.<span class="ruby-identifier">first</span>(<span class="ruby-value">3</span>).<span class="ruby-identifier">join</span>(<span class="ruby-identifier">$/</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-handle_error" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">handle_error</span><span
                                class="method-args">(e, re_raise: true, io: $stderr)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p><a href="SyntaxSuggest.html#method-c-handle_error"><code>SyntaxSuggest.handle_error</code></a> [Public]</p>

<p>Takes a ‘SyntaxError` exception, uses the error message to locate the file. Then the file will be analyzed to find the location of the syntax error and emit that location to stderr.</p>

<p>Example:</p>

<pre class="ruby"><span class="ruby-keyword">begin</span>
  <span class="ruby-identifier">require</span> <span class="ruby-string">&#39;bad_file&#39;</span>
<span class="ruby-keyword">rescue</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">e</span>
  <span class="ruby-constant">SyntaxSuggest</span>.<span class="ruby-identifier">handle_error</span>(<span class="ruby-identifier">e</span>)
<span class="ruby-keyword">end</span>
</pre>

<p>By default it will re-raise the exception unless ‘re_raise: false`. The message output location can be configured using the `io: $stderr` input.</p>

<p>If a valid filename cannot be determined, the original exception will be re-raised (even with ‘re_raise: false`).</p>

                              <div class="method-source-code" id="handle_error-source">
            <pre><span class="ruby-comment"># File syntax_suggest/api.rb, line 41</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">handle_error</span>(<span class="ruby-identifier">e</span>, <span class="ruby-value">re_raise:</span> <span class="ruby-keyword">true</span>, <span class="ruby-value">io:</span> <span class="ruby-identifier">$stderr</span>)
  <span class="ruby-keyword">unless</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">SyntaxError</span>)
    <span class="ruby-identifier">io</span>.<span class="ruby-identifier">puts</span>(<span class="ruby-node">&quot;SyntaxSuggest: Must pass a SyntaxError, got: #{e.class}&quot;</span>)
    <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">file</span> = <span class="ruby-constant">PathnameFromMessage</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>, <span class="ruby-value">io:</span> <span class="ruby-identifier">io</span>).<span class="ruby-identifier">call</span>.<span class="ruby-identifier">name</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">file</span>

  <span class="ruby-identifier">io</span>.<span class="ruby-identifier">sync</span> = <span class="ruby-keyword">true</span>

  <span class="ruby-identifier">call</span>(
    <span class="ruby-value">io:</span> <span class="ruby-identifier">io</span>,
    <span class="ruby-value">source:</span> <span class="ruby-identifier">file</span>.<span class="ruby-identifier">read</span>,
    <span class="ruby-value">filename:</span> <span class="ruby-identifier">file</span>
  )

  <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">re_raise</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-invalid-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">invalid?</span><span
                                class="method-args">(source)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p><a href="SyntaxSuggest.html#method-c-invalid-3F"><code>SyntaxSuggest.invalid?</code></a> [Private]</p>

<p>Opposite of ‘SyntaxSuggest.valid?`</p>

                              <div class="method-source-code" id="invalid-3F-source">
            <pre><span class="ruby-comment"># File syntax_suggest/api.rb, line 132</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">invalid?</span>(<span class="ruby-identifier">source</span>)
  <span class="ruby-identifier">source</span> = <span class="ruby-identifier">source</span>.<span class="ruby-identifier">join</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">source</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>)
  <span class="ruby-identifier">source</span> = <span class="ruby-identifier">source</span>.<span class="ruby-identifier">to_s</span>

  <span class="ruby-constant">Ripper</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">source</span>).<span class="ruby-identifier">tap</span>(<span class="ruby-operator">&amp;</span><span class="ruby-value">:parse</span>).<span class="ruby-identifier">error?</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-module_for_detailed_message" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">module_for_detailed_message</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p><a href="SyntaxSuggest.html#method-c-module_for_detailed_message"><code>SyntaxSuggest.module_for_detailed_message</code></a> [Private]</p>

<p>Used to monkeypatch SyntaxError via Module.prepend</p>

                              <div class="method-source-code" id="module_for_detailed_message-source">
            <pre><span class="ruby-comment"># File syntax_suggest/core_ext.rb, line 27</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">module_for_detailed_message</span>
  <span class="ruby-constant">Module</span>.<span class="ruby-identifier">new</span> {
    <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">detailed_message</span>(<span class="ruby-value">highlight:</span> <span class="ruby-keyword">true</span>, <span class="ruby-value">syntax_suggest:</span> <span class="ruby-keyword">true</span>, <span class="ruby-operator">**</span><span class="ruby-identifier">kwargs</span>)
      <span class="ruby-keyword">return</span> <span class="ruby-keyword">super</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">syntax_suggest</span>

      <span class="ruby-identifier">require</span> <span class="ruby-string">&quot;syntax_suggest/api&quot;</span> <span class="ruby-keyword">unless</span> <span class="ruby-keyword">defined?</span>(<span class="ruby-constant">SyntaxSuggest</span><span class="ruby-operator">::</span><span class="ruby-constant">DEFAULT_VALUE</span>)

      <span class="ruby-identifier">message</span> = <span class="ruby-keyword">super</span>

      <span class="ruby-keyword">if</span> <span class="ruby-identifier">path</span>
        <span class="ruby-identifier">file</span> = <span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>)
        <span class="ruby-identifier">io</span> = <span class="ruby-constant">SyntaxSuggest</span><span class="ruby-operator">::</span><span class="ruby-constant">MiniStringIO</span>.<span class="ruby-identifier">new</span>

        <span class="ruby-constant">SyntaxSuggest</span>.<span class="ruby-identifier">call</span>(
          <span class="ruby-value">io:</span> <span class="ruby-identifier">io</span>,
          <span class="ruby-value">source:</span> <span class="ruby-identifier">file</span>.<span class="ruby-identifier">read</span>,
          <span class="ruby-value">filename:</span> <span class="ruby-identifier">file</span>,
          <span class="ruby-value">terminal:</span> <span class="ruby-identifier">highlight</span>
        )
        <span class="ruby-identifier">annotation</span> = <span class="ruby-identifier">io</span>.<span class="ruby-identifier">string</span>

        <span class="ruby-identifier">annotation</span> <span class="ruby-operator">+=</span> <span class="ruby-string">&quot;\n&quot;</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">annotation</span>.<span class="ruby-identifier">end_with?</span>(<span class="ruby-string">&quot;\n&quot;</span>)

        <span class="ruby-identifier">annotation</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">message</span>
      <span class="ruby-keyword">else</span>
        <span class="ruby-identifier">message</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">rescue</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">e</span>
      <span class="ruby-keyword">if</span> <span class="ruby-constant">ENV</span>[<span class="ruby-string">&quot;SYNTAX_SUGGEST_DEBUG&quot;</span>]
        <span class="ruby-identifier">$stderr</span>.<span class="ruby-identifier">warn</span>(<span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>)
        <span class="ruby-identifier">$stderr</span>.<span class="ruby-identifier">warn</span>(<span class="ruby-identifier">e</span>.<span class="ruby-identifier">backtrace</span>)
      <span class="ruby-keyword">end</span>

      <span class="ruby-comment"># Ignore internal errors</span>
      <span class="ruby-identifier">message</span>
    <span class="ruby-keyword">end</span>
  }
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-record_dir" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">record_dir</span><span
                                class="method-args">(dir)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p><a href="SyntaxSuggest.html#method-c-record_dir"><code>SyntaxSuggest.record_dir</code></a> [Private]</p>

<p>Used to generate a unique directory to record search steps for debugging</p>

                              <div class="method-source-code" id="record_dir-source">
            <pre><span class="ruby-comment"># File syntax_suggest/api.rb, line 89</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">record_dir</span>(<span class="ruby-identifier">dir</span>)
  <span class="ruby-identifier">time</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>.<span class="ruby-identifier">strftime</span>(<span class="ruby-string">&quot;%Y-%m-%d-%H-%M-%s-%N&quot;</span>)
  <span class="ruby-identifier">dir</span> = <span class="ruby-constant">Pathname</span>(<span class="ruby-identifier">dir</span>)
  <span class="ruby-identifier">dir</span>.<span class="ruby-identifier">join</span>(<span class="ruby-identifier">time</span>).<span class="ruby-identifier">tap</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">path</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">path</span>.<span class="ruby-identifier">mkpath</span>
    <span class="ruby-identifier">alias_dir</span> = <span class="ruby-identifier">dir</span>.<span class="ruby-identifier">join</span>(<span class="ruby-string">&quot;last&quot;</span>)
    <span class="ruby-constant">FileUtils</span>.<span class="ruby-identifier">rm_rf</span>(<span class="ruby-identifier">alias_dir</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">alias_dir</span>.<span class="ruby-identifier">exist?</span>
    <span class="ruby-constant">FileUtils</span>.<span class="ruby-identifier">ln_sf</span>(<span class="ruby-identifier">time</span>, <span class="ruby-identifier">alias_dir</span>)
  }
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-valid-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">valid?</span><span
                                class="method-args">(source)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p><a href="SyntaxSuggest.html#method-c-valid-3F"><code>SyntaxSuggest.valid?</code></a> [Private]</p>

<p>Returns truthy if a given input source is valid syntax</p>

<pre class="ruby"><span class="ruby-constant">SyntaxSuggest</span>.<span class="ruby-identifier">valid?</span>(<span class="ruby-identifier">&lt;&lt;~EOM</span>) <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-value">  def foo
  end
</span><span class="ruby-identifier">EOM</span>

<span class="ruby-constant">SyntaxSuggest</span>.<span class="ruby-identifier">valid?</span>(<span class="ruby-identifier">&lt;&lt;~EOM</span>) <span class="ruby-comment"># =&gt; false</span>
<span class="ruby-value">  def foo
    def bar # Syntax error here
  end
</span><span class="ruby-identifier">EOM</span>
</pre>

<p>You can also pass in an array of lines and they’ll be joined before evaluating</p>

<pre class="ruby"><span class="ruby-constant">SyntaxSuggest</span>.<span class="ruby-identifier">valid?</span>(
  [
    <span class="ruby-string">&quot;def foo\n&quot;</span>,
    <span class="ruby-string">&quot;end\n&quot;</span>
  ]
) <span class="ruby-comment"># =&gt; true</span>

<span class="ruby-constant">SyntaxSuggest</span>.<span class="ruby-identifier">valid?</span>(
  [
    <span class="ruby-string">&quot;def foo\n&quot;</span>,
    <span class="ruby-string">&quot;  def bar\n&quot;</span>, <span class="ruby-comment"># Syntax error here</span>
    <span class="ruby-string">&quot;end\n&quot;</span>
  ]
) <span class="ruby-comment"># =&gt; false</span>
</pre>

<p>As an FYI the <a href="SyntaxSuggest/CodeLine.html"><code>CodeLine</code></a> class instances respond to ‘to_s` so passing a <a href="SyntaxSuggest/CodeLine.html"><code>CodeLine</code></a> in as an object or as an array will convert it to it’s code representation.</p>

                              <div class="method-source-code" id="valid-3F-source">
            <pre><span class="ruby-comment"># File syntax_suggest/api.rb, line 175</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">valid?</span>(<span class="ruby-identifier">source</span>)
  <span class="ruby-operator">!</span><span class="ruby-identifier">invalid?</span>(<span class="ruby-identifier">source</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-valid_without-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">valid_without?</span><span
                                class="method-args">(without_lines:, code_lines:)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p><a href="SyntaxSuggest.html#method-c-valid_without-3F"><code>SyntaxSuggest.valid_without?</code></a> [Private]</p>

<p>This will tell you if the ‘code_lines` would be valid if you removed the `without_lines`. In short it’s a way to detect if we’ve found the lines with syntax errors in our document yet.</p>

<pre>code_lines = [
  CodeLine.new(line: &quot;def foo\n&quot;,   index: 0)
  CodeLine.new(line: &quot;  def bar\n&quot;, index: 1)
  CodeLine.new(line: &quot;end\n&quot;,       index: 2)
]

SyntaxSuggest.valid_without?(
  without_lines: code_lines[1],
  code_lines: code_lines
)                                    # =&gt; true

SyntaxSuggest.valid?(code_lines) # =&gt; false</pre>

                              <div class="method-source-code" id="valid_without-3F-source">
            <pre><span class="ruby-comment"># File syntax_suggest/api.rb, line 119</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">valid_without?</span>(<span class="ruby-value">without_lines:</span>, <span class="ruby-value">code_lines:</span>)
  <span class="ruby-identifier">lines</span> = <span class="ruby-identifier">code_lines</span> <span class="ruby-operator">-</span> <span class="ruby-constant">Array</span>(<span class="ruby-identifier">without_lines</span>).<span class="ruby-identifier">flatten</span>

  <span class="ruby-keyword">if</span> <span class="ruby-identifier">lines</span>.<span class="ruby-identifier">empty?</span>
    <span class="ruby-keyword">true</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">valid?</span>(<span class="ruby-identifier">lines</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-detailed_message" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">detailed_message</span><span
                                class="method-args">(highlight: true, syntax_suggest: true, **kwargs)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              
                                <div class="method-calls-super">
                                  Calls superclass method
                                  
                              </div>

                              <div class="method-source-code" id="detailed_message-source">
            <pre><span class="ruby-comment"># File syntax_suggest/core_ext.rb, line 29</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">detailed_message</span>(<span class="ruby-value">highlight:</span> <span class="ruby-keyword">true</span>, <span class="ruby-value">syntax_suggest:</span> <span class="ruby-keyword">true</span>, <span class="ruby-operator">**</span><span class="ruby-identifier">kwargs</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">super</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">syntax_suggest</span>

  <span class="ruby-identifier">require</span> <span class="ruby-string">&quot;syntax_suggest/api&quot;</span> <span class="ruby-keyword">unless</span> <span class="ruby-keyword">defined?</span>(<span class="ruby-constant">SyntaxSuggest</span><span class="ruby-operator">::</span><span class="ruby-constant">DEFAULT_VALUE</span>)

  <span class="ruby-identifier">message</span> = <span class="ruby-keyword">super</span>

  <span class="ruby-keyword">if</span> <span class="ruby-identifier">path</span>
    <span class="ruby-identifier">file</span> = <span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>)
    <span class="ruby-identifier">io</span> = <span class="ruby-constant">SyntaxSuggest</span><span class="ruby-operator">::</span><span class="ruby-constant">MiniStringIO</span>.<span class="ruby-identifier">new</span>

    <span class="ruby-constant">SyntaxSuggest</span>.<span class="ruby-identifier">call</span>(
      <span class="ruby-value">io:</span> <span class="ruby-identifier">io</span>,
      <span class="ruby-value">source:</span> <span class="ruby-identifier">file</span>.<span class="ruby-identifier">read</span>,
      <span class="ruby-value">filename:</span> <span class="ruby-identifier">file</span>,
      <span class="ruby-value">terminal:</span> <span class="ruby-identifier">highlight</span>
    )
    <span class="ruby-identifier">annotation</span> = <span class="ruby-identifier">io</span>.<span class="ruby-identifier">string</span>

    <span class="ruby-identifier">annotation</span> <span class="ruby-operator">+=</span> <span class="ruby-string">&quot;\n&quot;</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">annotation</span>.<span class="ruby-identifier">end_with?</span>(<span class="ruby-string">&quot;\n&quot;</span>)

    <span class="ruby-identifier">annotation</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">message</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">message</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">rescue</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">e</span>
  <span class="ruby-keyword">if</span> <span class="ruby-constant">ENV</span>[<span class="ruby-string">&quot;SYNTAX_SUGGEST_DEBUG&quot;</span>]
    <span class="ruby-identifier">$stderr</span>.<span class="ruby-identifier">warn</span>(<span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>)
    <span class="ruby-identifier">$stderr</span>.<span class="ruby-identifier">warn</span>(<span class="ruby-identifier">e</span>.<span class="ruby-identifier">backtrace</span>)
  <span class="ruby-keyword">end</span>

  <span class="ruby-comment"># Ignore internal errors</span>
  <span class="ruby-identifier">message</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>. </p><p><a href="https://jamesbritt.bandcamp.com/">Hack your world.  Feed your head.  Live curious</a>.</p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

